﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace Kokomo.Mirror.CliMetadata
{
	public class CliExceptionHandlingClause : ExceptionHandlingClause
	{
		internal CliExceptionHandlingClause(
			CliModule module,
			int tryOffset,
			int tryLength,
			int filterOffset,
			int typeToken,
			int handlerOffset,
			int handlerLength
			)
			: base()
		{
			if ((object)module == null) throw new ArgumentNullException("module");

			this._module = module;

			this._module = module;
			this._tryOffset = tryOffset;
			this._tryLength = tryLength;
			this._filterOffset = filterOffset;
			this._typeToken = typeToken;
			this._handlerOffset = handlerOffset;
			this._handlerLength = handlerLength;
		}

		private CliModule _module;

		private ExceptionHandlingClauseOptions _flags;
		public override ExceptionHandlingClauseOptions Flags
		{
			get { return this._flags; }
		}

		#region Try
		private int _tryOffset;
		public override int TryOffset
		{
			get { return this._tryOffset; }
		}

		private int _tryLength;
		public override int TryLength
		{
			get { return this._tryLength; }
		}
		#endregion
		#region Filter
		private int _filterOffset;
		public override int FilterOffset
		{
			get { return this._filterOffset; }
		}
		#endregion
		#region Handler
		private int _handlerOffset;
		public override int HandlerOffset
		{
			get { return this._handlerOffset; }
		}

		private int _handlerLength;
		public override int HandlerLength
		{
			get { return this._handlerLength; }
		}

		private int _typeToken;
		public override Type CatchType
		{
			get
			{
				return (this._typeToken == 0) ? null : this._module.ResolveType(this._typeToken);
			}
		}
		#endregion
	}
}
